import * as THREE from "three";

import { idToName, loadModel2 } from "@/script/utils/index";

const modelGroup: THREE.Group = new THREE.Group();
let collisionModel: THREE.Object3D | null = null;

async function initialize() {
  const sceneJsonResponse = await fetch("/sceneJson/station.json");
  const sceneData = await sceneJsonResponse.json();

  const _listResponse = await fetch("/sceneJson/_list.json");
  const modelNameArray = await _listResponse.json();

  for await (const model of sceneData.models) {
    const modelName = idToName(model.modelId, modelNameArray);

    const nodeLevel1 = await loadModel2(
      modelName,
      model.code,
      modelGroup,
      model.position,
      model.rotation,
      model.scale,
      model.visible
    );

    if (modelName == "Station_pengzhuang") {
      collisionModel = nodeLevel1;
    }
    console.log("nodeLevel1", nodeLevel1);
  }
}


export {initialize,modelGroup, collisionModel };
